package com.rjxy.plansystemmanagement.controller.entityController;

import com.rjxy.plansystemmanagement.entity.AirlinerInformation;
import com.rjxy.plansystemmanagement.entity.Result.Result;
import com.rjxy.plansystemmanagement.service.AirlinerService;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/Airliners")
public class AirlinerController {
    @Autowired
    private AirlinerService airlinerService;

    /**
     * 查询所有客机
     * @return
     */
    @GetMapping
    public Result list(){
        log.info("查询客机列表");
        List<AirlinerInformation> airlinerInformationList=airlinerService.list();
        return Result.success(airlinerInformationList);
    }

    /**
     * 根据id删除客机
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteAirliner(@PathVariable Integer id){
        log.info("根据id{}删除客机",id);
        airlinerService.deleteAirliner(id);
        return Result.success();
    }

    /**
     * 增加客机
     * @param airlinerInformation
     * @return
     */
    @PostMapping
    public Result addAirliner(@RequestBody AirlinerInformation airlinerInformation){
        log.info("增加客机");
        airlinerService.addAirliner(airlinerInformation);
        return Result.success();
    }

    /**
     * 根据id查询指定客机
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getAirlinerById(@PathVariable Integer id){
        log.info("根据id{}查询指定客机",id);
        AirlinerInformation airlinerInformation = airlinerService.getAirlinerById(id);
        return Result.success(airlinerInformation);
    }

    /**
     * 更新id的客机
     * @param airlinerInformation
     * @return
     */
    @PutMapping
    public Result updateAirliner(@RequestBody AirlinerInformation airlinerInformation){
        log.info("更新id{}的客机",airlinerInformation.getID());
        airlinerService.updateAirliner(airlinerInformation);
        return Result.success();
    }
}
